package cn.coder.controller;


import cn.coder.mapper.AccountMapper;
import com.taobao.txc.common.TxcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    AccountMapper accountMapper;


    @PostMapping("/add")
    public void add(Integer count) {
        String xid = TxcContext.getCurrentXid();
        System.out.println("事务传递xid为：" + xid);
        accountMapper.add(count);
     //   throw new RuntimeException();
    }


    @PostMapping("/reduce")
    public void reduce(Integer count) {
        String xid = TxcContext.getCurrentXid();
        System.out.println("事务传递xid为：" + xid);
        accountMapper.reduce(count);
    }
}
